from selenium import webdriver
import time

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys #键盘事件
from selenium.webdriver.support.select import Select #下拉菜单
from selenium.webdriver.common.by import By



drivr= webdriver.Edge()
drivr.maximize_window()

drivr.get('https://www.jiuxian.com/')
time.sleep(10)

# 业务用例
# 1.点击请登录
drivr.find_element(By.LINK_TEXT,'请登录').click()
time.sleep(2)
#2.输入账号
drivr.find_element(By.ID,'userName').send_keys('17733058407')
time.sleep(2)

#3.输入密码
drivr.find_element(By.XPATH,'//*[@id="password"]').send_keys('Li10140910')
time.sleep(20)

#4.点击登录
drivr.find_element(By.NAME,'bi_Usuallogin').click()
time.sleep(2)
# 6 点击 确定
drivr.find_element(By.XPATH,'//a[@id="bindSub"]').click()
time.sleep(2)
# 校验点：hi，jxw543475854
dy = drivr.find_element(By.XPATH,'/html/body/div[2]/div/div[1]/div/p/span').text
print(dy)
time.sleep(2)
# 7 点击 我的酒仙
drivr.find_element(By.XPATH,'/html/body/div[2]/div/div[2]/ul/li[1]/div[1]/a').click()
time.sleep(2)
# 8 切换窗口
drivr.switch_to.window(drivr.window_handles[-1])
time.sleep(10)

#9 向下滚动
drivr.execute_script('window.scrollTo(0,600)')
time.sleep(4)
# 10 点击收货地址
drivr.find_element(By.XPATH,'/html/body/div[4]/div[1]/div[2]/div[4]/a[3]').click()
time.sleep(4)

#11 添加收件人
drivr.find_element(By.XPATH,'//*[@id="people"]').send_keys('李先生')
time.sleep(4)

#12 选择省
province = Select(drivr.find_element(By.ID, 'province'))
province.select_by_index(1)
time.sleep(2)
#13 选择 市
city = Select(drivr.find_element(By.ID, 'city'))
city.select_by_value("52")
time.sleep(2)
#14 选择 区
dis = Select(drivr.find_element(By.ID, 'district'))
dis.select_by_visible_text("昌平区")
time.sleep(2)